import { useAuthStore } from "@/store"
import { isArray, isEmpty, isString } from "@/utils"

/**
 * 权限配置
 */
export interface PermissionProps {
    // 权限码
    permissions?: string | string[]
}

/**
 * 判断有权限
 */
export function hasPermission(props: PermissionProps): boolean {
    const { permissions } = props
    if (isEmpty(permissions)) {
        return true
    }
    const authStore = useAuthStore()
    if (isString(permissions)) {
        return authStore.hasPermission(permissions as string)
    }
    if (isArray(permissions)) {
        return authStore.hasPermissions(permissions as string[])
    }
    console.log("权限配置格式错误：%s", permissions)
    return false
}
